﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T.S.BaseData.Infrastructure.Base
{
    /// <summary>
    /// 仓储类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BaseRepository<T> : IBaseRepository<T> where T : class
    {
        private readonly MyDbContext db;

        public BaseRepository(MyDbContext db)
        {
            this.db = db;
        }

        public int Crate(T t)
        {
            db.Set<T>().Add(t);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>();
        }

        public T GetModel(int Id)
        {
            return db.Set<T>().Find(Id);
        }

        public int Update(T t)
        {
            db.Set<T>().Update(t);
            return db.SaveChanges();
        }
    }
}
